﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Battleship_569.Data
{
    // TinNT - Manage ship
    class Battleship
    {
        private int type = 0;
        private int length = 0;
        private int[] location;
        private bool sunk = false;
        private bool Wreck = false;
        private int hits = 0;
        private string direction = "down";
        //private int setLength = 0;
        private int _X = 0;
        private int _Y = 0;

        // Constructor - Creates a ship
        public Battleship(int type, int length, int x, int y, string direction)
        {
            this.type = type;
            this.length = length;
            this._X = x;
            this._Y = y;
            this.direction = direction;
            this.sunk = false;
            // chưa rõ location
            this.location = new int[length];
        }

        // Get Direction of Ship

        public string getDirection()
        {
            return this.direction;
        }

        // Get position X from Grid
        public int get_X()
        {
            return this._X;
        }

        // Get position Y from Grid
        public int get_Y()
        {
            return this._Y;
        }

        // Set position X,Y from Grid
        public void set_XY(int x, int y)
        {
            this._X = x;
            this._Y = y;
        }

        // Tingo **********************************************
        // makes the ship know where it is. - unclear
        //public void setLocation(int x, int y)
        //{  
        //    this.location[setLength] = ((x*10) + y);
        //    this.setLength++;  	
        //}
        // **********************************************

        // get the location
        public int[] getLocation()
        {
            return location;
        }

        // set hit
        public void setHit()
        {
            this.hits = hits + 1;
            setSunk();
        }

        //set sunk indicates the ship is sunk
        public void setSunk()
        {
            if (hits == length)
            {
                //System.Windows.Forms.MessageBox.Show("I'm Sunk");  	  		
                this.sunk = true;
            }
        }

        //is a wreck returns true if ship has sunk.
        public bool isAWreck()
        {
            if (!Wreck)
            {
                Wreck = true;
                return this.Wreck;
            }

            return false;
        }

        //is sunk returns true if ship is sunk.
        public bool isSunk()
        {
            return this.sunk;
        }

        // TinNT - Set length of ship
        public void setLength(int length)
        {
            this.length = length;
        }

        // get length of ship
        public int getLength()
        {
            return this.length;
        }

        // TinNT 
        public void setType(int type)
        {
            this.type = type;
        }

        // get type of ship
        public int getType()
        {
            // 0 Ocean 
            // 1 aircraft length 6 - 1
            // 2 destroyer length 5 - 2;
            // 3 cruiser length 4 - 2;
            // 3 submarine length 3 - 3;
            // 3 Patrol ship length 2 - 3;
            // 8 missle hit
            // 9 missle no hit

            return this.type;
        }

    }
}
